package lab03.test11;

import java.sql.*;
//11、	安装Navicat软件，创建一个名为java_2017 的数据库（字符集采用utf8），
// 在该数据库下创建t_users表，表的各字段及类型如下：
public class Test11 {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        String sql1 = "create database java_2017";

        String sql2 = "create table t_users(" +
                "id int primary key," +
                "username VARCHAR(200) NOT NULL ," +
                "password VARCHAR (200) NOT NULL ," +
                "register long NOT NULL " +
                ")";

        String sql3 = "insert into t_users " +
                "SELECT 1,'admin','admin',192312312123 UNION " +
                "SELECT 2,'chen','123456',123123213123";

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC&characterEncoding=utf-8","root","123456");

            statement = connection.createStatement();

//            statement.execute(sql1);

//            statement.execute(sql2);

            statement.execute(sql3);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

